/**
 * 由 WangYu 创建
 * 日期 2017/10/18
 */
import React, {Component} from 'react';
import {
    StyleSheet,
    Text,
    View,
    Image,
    TouchableOpacity, TextInput,
} from 'react-native';
import Toast from "teaset/components/Toast/Toast";
import Button from "../../view/Button";
import NetUtils from "../../util/NetUtils";
import Spinner from "../../view/Spinner";
import {Actions} from "react-native-router-flux";
import Api from "../../util/Api";
export default class FeedBackPage extends Component {

    constructor(props) {
        super(props);
        this.state = {
            text: '',
            progressVisible:false,
        }
    }

    render() {
        return (
            <View style={styles.container}>
                <Text style={{height: 50, backgroundColor: 'white', textAlignVertical: 'center', paddingLeft: 10}}>请问您想反馈哪些意见?</Text>
                <View>
                    <TextInput style={styles.textInputStyle}
                               underlineColorAndroid={'transparent'}
                               placeholder={'感谢您关注我们,我们力求为您提供更优质,高效的服务,期待您的宝贵意见'}
                               placeholderTextColor={'#d5d5d5'}
                               multiline={true}
                               onChangeText={text => this.setState({text: text})}
                               onSubmitEditing={() => Toast.message('提交')}>
                    </TextInput>
                    <Text style={{
                        position: 'absolute',
                        right: 30,
                        bottom: 30,
                        color: '#cccccc',
                        fontSize: 12
                    }}>可输入500字</Text>
                </View>
                <Button title={'提交'} onPress={() => this.submit()} style={{marginTop: 15,marginLeft:15,marginRight:15}}/>
                <Spinner cancelable={true} visible={this.state.progressVisible} textContent={"提交中..."} textStyle={{color: '#FFF'}} />
            </View>
        );
    }

    submit(){
        this.state.text===''&&Toast.message('内容不能为空');
        let params='content='+this.state.text;
        this.setState({progressVisible:true});
        NetUtils.post(Api.feedback,params,result=>{
            if(result.code===1){
                Toast.message('反馈成功');
                Actions.pop();
            }
        },()=>{  this.setState({progressVisible:false});})
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#f8f8f8'
    },
    textInputStyle: {
        height: 400,
        backgroundColor: 'white',
        borderRadius: 3,
        borderWidth: 0.5,
        borderColor: '#aaaaaa',
        padding: 10,
        color: '#010101',
        textAlignVertical: 'top',
        margin: 10
    }
});
